package com.ruoyi.web.controller.productManagement;


import java.util.List;
import javax.servlet.http.HttpServletResponse;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.system.domain.AccessoryCategory;
import com.ruoyi.system.service.IAccessoryCategoryService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 配品分类管理 Controller
 *
 * @author ruoyi
 * @date 2025-05-24
 */
@Api(tags="配品分类管理")
@RestController
@RequestMapping("/system/accessoryCategory")
public class AccessoryCategoryController extends BaseController
{
    @Autowired
    private IAccessoryCategoryService accessoryCategoryService;

    /**
     * 通过分类名称查询配品分类管理列表
     */
    @ApiOperation("通过分类名称查询配品分类管理列表")
    @PreAuthorize("@ss.hasPermi('system:category:list')")
    @GetMapping("/list")
    public TableDataInfo list(@RequestParam (required = false) String categoryName)
    {
        startPage();
        List<AccessoryCategory> list = accessoryCategoryService.selectAccessoryCategoryListByName(categoryName);
        return getDataTable(list);
    }

    /**
     * 导出配品分类管理列表
     */
    @ApiOperation("导出配品分类管理列表")
    @PreAuthorize("@ss.hasPermi('system:category:export')")
    @Log(title = "配品分类管理", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, @RequestParam (required = false) String categoryName)
    {
        List<AccessoryCategory> list = accessoryCategoryService.selectAccessoryCategoryListByName(categoryName);
        ExcelUtil<AccessoryCategory> util = new ExcelUtil<AccessoryCategory>(AccessoryCategory.class);
        util.exportExcel(response, list, "配品分类管理");
    }

    /**
     * 通过id获取配品分类管理详细信息
     */
    @ApiOperation("通过id获取配品分类管理详细信息")
    @PreAuthorize("@ss.hasPermi('system:category:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return success(accessoryCategoryService.selectAccessoryCategoryById(id));
    }

    /**
     * 新增配品分类管理
     */
    @ApiOperation("新增配品分类管理")
    @PreAuthorize("@ss.hasPermi('system:category:add')")
    @Log(title = "配品分类管理", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody AccessoryCategory accessoryCategory)
    {
        return toAjax(accessoryCategoryService.insertAccessoryCategory(accessoryCategory));
    }

    /**
     * 修改配品分类管理
     */
    @ApiOperation("修改配品分类管理")
    @PreAuthorize("@ss.hasPermi('system:category:edit')")
    @Log(title = "配品分类管理", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody AccessoryCategory accessoryCategory)
    {
        return toAjax(accessoryCategoryService.updateAccessoryCategory(accessoryCategory));
    }

    /**
     * 通过id批量删除配品分类管理信息
     */
    @ApiOperation("通过id批量删除配品分类管理信息")
    @PreAuthorize("@ss.hasPermi('system:category:remove')")
    @Log(title = "配品分类管理", businessType = BusinessType.DELETE)
    @DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(accessoryCategoryService.deleteAccessoryCategoryByIds(ids));
    }
}
